<?php

namespace support;

class Store
{
    protected $driver;

    public function __construct($driver)
    {
        $this->driver = new $driver;
    }

    public static function autoGetInstance()
    {
        if ($store = getenv('STORE_DRIVER')) {
            if ($store == 'FILE') {
                return new self(FileStore::class);
            } else if ($store == 'QINIU') {
                return new self(QiNiuStore::class);
            }
        }
    }

    public function upload($file)
    {
        return $this->driver->upload($file);
    }

    public function __call($name, $arguments)
    {
        return $this->driver->{$name}(...$arguments);
    }
}